package com.bkhc.product.api.inter;

import com.bkhc.common.annotation.ApiOperation;
import com.bkhc.common.annotation.ApiPackage;
import com.bkhc.common.annotation.AuditLog;
import com.bkhc.common.enu.OperationEnum;
import com.bkhc.common.util.response.ResultJson;
import com.bkhc.product.entity.*;
import com.bkhc.product.service.*;
import com.bkhc.product.vo.GoodsPriceVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/common")
@Api("内部公共服务")
@ApiPackage(code="common-api",name="内部公共服务",description = "内部公共服务")
public class BrandProductApi {

    @Autowired
    private BrandProductService brandProductService;

    @Autowired
    private ProductService productService;

    @Autowired
    private BrandService brandService;

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private GoodsSpecService goodsSpecService;


    @ApiOperation(code="getBrandProductFromPartner",name="查询品牌厂商的产品列表",description = "查询品牌厂商的产品列表",type = "common")
    @AuditLog(object="getBrandProductFromPartner",operation = "查询品牌厂商的产品列表",type = OperationEnum.query)
    @RequestMapping(path = "/brand/products",method = RequestMethod.POST)
    public ResultJson<?> getBrandProducts(@RequestParam(name = "brandCode")String brandCode,@RequestParam(name="partnerCode")String partnerCode) {
        ResultJson<?> res = brandProductService.getBrandProductByBrandCodeAndPartnerCode(brandCode,partnerCode);
        return res;
    }

    @ApiOperation(code="getProductSpecFromPartner",name="获取产品的规格",description = "查询品牌的产品列表",type = "common")
    @AuditLog(object="getProductSpecFromPartner",operation = "获取产品的规格",type = OperationEnum.query)
    @RequestMapping(path = "/brand/product/spec",method = RequestMethod.POST)
    public ResultJson<?> getProductSpec(@RequestParam(name = "productCode")String productCode) {
        ResultJson<?> res = productService.getProductSpec(productCode);
        return res;
    }

    @ApiOperation(code="getBrandProductGoodsFromPartner",name="获取品牌产品的商品",description = "获取品牌产品的商品",type = "common")
    @AuditLog(object="getBrandProductGoodsFromPartner",operation = "获取品牌产品的商品",type = OperationEnum.query)
    @RequestMapping(path = "/brand/product/goods",method = RequestMethod.POST)
    public ResultJson<?> getBrandProductGoods(@RequestParam(name = "productCode")String productCode,@RequestParam(name = "brandCode")String brandCode) {
        ResultJson<?> res = brandService.getBrandGoodsByProductAndBrand(productCode,brandCode);
        return res;
    }

    @ApiOperation(code="getUploadPriceRule",name="获取品牌产品价格上传规则",description = "获取品牌产品的商品",type = "common")
    @AuditLog(object="getUploadPriceRule",operation = "获取品牌产品价格上传规则",type = OperationEnum.query)
    @RequestMapping(path = "/brand/product/price/rule",method = RequestMethod.POST)
    public ResultJson<?> getUploadPriceRule(@RequestParam(name = "productCode")String productCode,@RequestParam(name = "brandCode")String brandCode) {
        ResultJson<?> res = brandService.getUploadPriceRule(productCode,brandCode);
        return res;
    }

    @ApiOperation(code="queryUploadPrice",name="获取品牌产品价格上传价格",description = "获取品牌产品的商品",type = "common")
    @AuditLog(object="queryUploadPrice",operation = "获取品牌产品价格上传价格",type = OperationEnum.query)
    @RequestMapping(path = "/brand/product/price",method = RequestMethod.POST)
    public ResultJson<?> queryUploadPrice(@RequestParam(name = "productCode")String productCode,@RequestParam(name = "brandCode")String brandCode) {
        ResultJson<?> res = brandService.queryUploadPrice(productCode,brandCode);
        return res;
    }

    @ApiOperation(code="getProductForPartner",name="查询产品",description = "获取产品的详细信息",type = "common")
    @AuditLog(object="getProductForPartner",operation = "获取产品的详细信息",type = OperationEnum.query)
    @RequestMapping(path = "/product",method = RequestMethod.POST)
    public ResultJson<?> getProduct(@RequestParam(name = "productCode")String productCode) {
        ResultJson<?> res = productService.findProductDetail(productCode);
        return res;
    }

    @ApiOperation(code="getBrandForPartner",name="查询产品",description = "获取产品的详细信息",type = "common")
    @AuditLog(object="getBrandForPartner",operation = "获取产品的详细信息",type = OperationEnum.query)
    @RequestMapping(path = "/brand",method = RequestMethod.POST)
    public ResultJson<?> getBrand(@RequestParam(name = "brandCode")String brandCode) {
        ResultJson<?> res = brandService.getBrandByBrandCode(brandCode);
        return res;
    }

    @ApiOperation(code="updatePriceForPartner",name="上传价格",description = "上传价格",type = "common")
    @AuditLog(object="updatePriceForPartner",operation = "上传价格",type = OperationEnum.query)
    @RequestMapping(path = "/uploadPrice",method = RequestMethod.POST)
    public ResultJson<?> uploadPrice(@RequestBody List<BrandGoodPrice> brandGoodPrices) {
        ResultJson<?> res = brandService.uploadPrice(brandGoodPrices);
        return res;
    }

    @ApiOperation(code="getGoodsCodeListByList",name="获取商品属性",description = "获取商品属性",type = "common")
    @AuditLog(object="getGoodsCodeListByList",operation = "获取商品属性",type = OperationEnum.query)
    @RequestMapping(path = "/getGoodsCodeListByList",method = RequestMethod.POST)
    public List<GoodsSpec> getGoodsCodeListByList(@RequestBody List<String> goodsCodeList) {
        List<GoodsSpec> res = brandService.getGoodsCodeListByList(goodsCodeList);
        return res;
    }

    @ApiOperation(code="getBrandProductByPartner",name="厂商获取产品",description = "厂商获取产品",type = "common")
    @AuditLog(object="getGoodsCodeListByList",operation = "厂商获取产品",type = OperationEnum.query)
    @RequestMapping(path = "/getBrandProductByPartner/{pageNum}/{pageSize}",method = RequestMethod.GET)
    public ResultJson getBrandProductByPartner(@RequestParam(name = "partnerCode")String partnerCode, @PathVariable(required=false,name="pageNum") int pageIndex, @PathVariable(required=false,name="pageSize") int pageSize) {
        ResultJson res = brandProductService.getBrandProductByPartner(partnerCode,pageIndex,pageSize);
        return res;
    }

    @ApiOperation(code="getPartnerByBrandProduct",name="根据产品和品牌获取对应的供应商",description = "厂商获取产品",type = "common")
    @AuditLog(object="getPartnerByBrandProduct",operation = "根据产品和品牌获取对应的供应商",type = OperationEnum.query)
    @RequestMapping(path = "/getPartnerByBrandProduct",method = RequestMethod.GET)
    public PartnerBrand getPartnerByBrandProduct(@RequestParam(name = "productCode")String productCode,@RequestParam(name = "brandCode")String brandCode) {
        PartnerBrand res = brandProductService.getPartnerByBrandProduct(productCode,brandCode);
        return res;
    }

    @ApiOperation(code="getGoodsSpecByGoodsCode",name="根据商品编号获取规格",description = "下载订单获取规格",type = "common")
    @AuditLog(object="getGoodsSpecByGoodsCode",operation = "根据商品编号获取规格",type = OperationEnum.query)
    @RequestMapping(path = "/getGoodsSpecByGoodsCode",method = RequestMethod.POST)
    public ResultJson getGoodsSpecByGoodsCode(@RequestBody(required = false) List<String> goodsCodeIn) {
        System.out.println(goodsCodeIn.get(0));
        List<GoodsSpec> goodsSpecsMap = goodsSpecService.getGoods(goodsCodeIn);
        ResultJson res =new ResultJson();
        res.setData(goodsSpecsMap);
        return res;
    }



}
